package processingdata.airport;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class MergeAirports {
	
	public static void main(String args[])throws IOException
	{
		File file=new File("data/airporttrial.data");
		
		BufferedReader inputReader=new BufferedReader(new FileReader(new File("data/airporttrial.data")));
		BufferedWriter outputWriter=new BufferedWriter(new FileWriter(new File("data/airportfinal.data")));
		while(inputReader.ready())
		{
			String inputLine=inputReader.readLine();
			String inputLineParts[]=inputLine.split("\t");
			String gLatitude=inputLineParts[0].replaceAll("\\[", "").replaceAll("\\]", "");
			String gLongitude=inputLineParts[1].replaceAll("\\[", "").replaceAll("\\]", "");
			String fourCode=inputLineParts[2];
			String threeCode=inputLineParts[3];
			String airportName=inputLineParts[4];
			String place=inputLineParts[5];
			String country=inputLineParts[6];
			String geoLatitude=inputLineParts[7];
			String geoLongitude=inputLineParts[8];
			if(gLatitude.equals("") && gLongitude.equals(""))
			{
				outputWriter.write(fourCode+"\t"+threeCode+"\t"+airportName+"\t"+place+"\t"+country+"\t"+geoLatitude+"\t"+geoLongitude+"\n");
				
			}
			else
			{
				if(gLatitude.contains(",")&&gLongitude.contains(","))
				{
					outputWriter.write(fourCode+"\t"+threeCode+"\t"+airportName+"\t"+place+"\t"+country+"\t"+gLatitude.split(",")[0].trim()+"\t"+geoLongitude.split(",")[0].trim()+"\n");
				}
				else
				{
					outputWriter.write(fourCode+"\t"+threeCode+"\t"+airportName+"\t"+place+"\t"+country+"\t"+gLatitude.trim()+"\t"+gLongitude.trim()+"\n");
				}
			}
			
		}
		outputWriter.close();
	}

}
